module Erber
  def self.register(*extensions)
    extensions.each do |ext|
      ActionView::Base.register_template_handler ext, Erber.handler(ext)
    end
  end
  
  def self.handler(ext)
    klass = Class.new(Handler)
    klass.extension = ext
    klass
  end
  
  class Handler
    cattr_accessor :extension
    def initialize(view)
      @view = view
    end

    def render(template, local_assigns)
      @view.send :compile_and_render_template, @@extension, template, nil, local_assigns
    end
  end
end

